<?php
//include file
include("../include/session.php");
require_once('../db_conn/conn_db.php');
require_once('header.php');
require_once('../calendar/calendar/classes/tc_calendar.php');
require_once('../include/date.php');

$cari  = $_POST['s'];
$tgl_awal = $_POST['tgl_awal'];
$tgl_akhir = $_POST['tgl_akhir'];
$tglAwal_default = "2000-01-1";
$tglAkhir_default = "$Tahun-$Bulan1-30";

if ($cari == "Cari...")
	$cari ="";
	
if ($tgl_awal == "")
 $tgl_awal="$tglAwal_default";
 
if ($tgl_akhir == "") 
$tgl_akhir="$tglAkhir_default";


?>
<?php

$column_name=$_GET['column_name']; // Read the column name from query string. 
$limit=15; 
switch($limit)
{

case 5:
$selecta="";
$select5="selected";
$select10="";
$select2="";
break;

default:
$selecta="";
$select10="";
$select5="";
$select2="selected";
break;
}

$start=$_GET['start'];								// To take care global variable if OFF
if(!($start > 0)) {                         // This variable is set to zero for the first page
$start = 0;
}

$eu = ($start - 0); 
if(!$limit > 0 ){ // if limit value is not available then let us use a default value
$limit = 50;    // // Buat Jumlah Row PEr PAge Nehhhh
}                          
$this1 = $eu + $limit; 
$back = $eu - $limit; 
$next = $eu + $limit; 


/////////////// WE have to find out the number of records in our table. We will use this to break the pages///////
if ($role==2) $klien = "and klien.user_id = '$userid'";
$sql = "SELECT * from surat_perjanjian sp left join order_buku od on sp.order_id = od.id
		left join klien on od.klien_id = klien.id
        where sp.status=1 $klien ";
		
//echo "$sql";

$result2 = mysql_query($sql) or die(mysql_error());

$nume=mysql_num_rows($result2);
/////// The variable nume above will store the total number of records in the table////


if($nume > 0)
{
$bgcolor="#f1f1f1";
?>

<TABLE BORDER=1 align=left cellpadding=1 cellspacing=1>
<tr>
		<td class="pageName" colspan="7">Data Surat Perjanjian</td>
	</tr>
<TR>
	<TD BGCOLOR=#f32142> <div align=center>No. </div></TD>
	<TD BGCOLOR=#f32142> <div align=center>Klien</div></TD>
	<TD BGCOLOR=#f32142> <div align=center>Tema Buku</div></TD>
	<TD BGCOLOR=#f32142> <div align=center>Judul Buku</div></TD>
	<TD BGCOLOR=#f32142> <div align=center>Surat Perjanjian</div></TD>	
	<TD BGCOLOR=#f32142 colspan="2"> <div align=center>Action</div></TD>
</TR>
<?php

if(isset($column_name) and strlen($column_name)>0){
$sql = $sql. " order by $column_name";
}
$sql = $sql. " limit $eu, $limit ";
//echo "$sql";
$result = mysql_query($sql) or die(mysql_error());

if ($eu==0)
	$i=1; 
else 
	$i=$eu+1;

while($row = mysql_fetch_array($result))
{
	echo
 	"<tr>
	<td>$i</td>
	<td>$row[nama]</td>
	<td>$row[tema_buku]</td>
	<td>$row[judul_buku]</td>
	<td><a href=cetak_perjanjian.php?id=$row[0]>Clik Here to Print/View</a></td>
	<td><a href=form_perjanjian.php?id=$row[0]>Update</a></td> 
	<td><a href=save_perjanjian.php?action=delete&id=$row[0]>Delete</a></td>";
$i++;
}
echo "<tr><td colspan=11>
<table border=0 align=center>
<tr>
<td>";
if($back >=0) { 
print "<a href='$page_name?start=$back&column_name=$column_name&limit=$limit'><img src='img/prev_year.gif' border='0' /></a>"; 
} 
echo"</td><td>";
$i=0;
$l=1;
for($i=0;$i < $nume;$i=$i+$limit){
if($i <> $eu){
echo " <a href='$page_name?start=$i&column_name=$column_name&limit=$limit'><font face='Verdana' size='2'>$l</font></a> ";
}
else { echo "<font face='Verdana' size='2' color=red>$l</font>";}        /// Current page is not displayed as link and given font color red
$l=$l+1;
}
echo "</td><td>";
if($this1 < $nume) { 
print "<a href='$page_name?start=$next&column_name=$column_name&limit=$limit'><img src='img/next_year.gif' border='0'/></a>";} 
echo "</td></tr>
</table>";

} else {
echo"<p align='left'> &nbsp;
    <td class='style3' align='left'>Maaf Data Tidak Ditemukan</td></p>";
}
echo "</td>
</tr></table>";
//// if our variable $back is equal to 0 or more then only we will display the link to move back ////////

//////////////// Let us display the page links at  center. We will not display the current page as a link ///////////



///////////// If we are not in the last page then Next link will be displayed. Here we check that /////

?>
</form>
</div>
</BODY>
</HTML>
